package com.weibo.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class MySessionFactory {
	//hibernate工具类
	private static String CONFIG_FILE_LOCATION = "hibernate.cfg.xml";
	
	private static Session session = null;
	//private Transaction tx = null;
	private static Configuration config=null;
	private static SessionFactory sessionFactory = null;
	static {
		config = new Configuration().configure(CONFIG_FILE_LOCATION);
		sessionFactory = config.buildSessionFactory();
	}
	public static Session getSession()
	{
		//if(session==null) {
			session = sessionFactory.openSession();
			return session;
		//}
		//else return session;
	}
	public static void closeSession(){
		if(session== null) return ;
		else session.close();
	}
}
